/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DatosCliente.java
 *
 * Created on 06-dic-2010, 13:09:32
 */
package proyectoempresa.igu;

import Reportes.IniciarReporte;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import jcnumeroletra.GeneraLetras;
import proyectoempresa.DAO.FacturaDao;
import proyectoempresa.DAO.InventarioDao;
import proyectoempresa.DAO.LineaFacturaDao;
import proyectoempresa.DAO.ContenedorReporteGeneralCuentasDao;
import proyectoempresa.modelo.Factura;
import proyectoempresa.modelo.Inventario;
import proyectoempresa.modelo.Lineafactura;
import proyectoempresa.modelo.ContenedorReporteGeneralCuentas;
import proyectoempresa.modeloTabla.ModeloTablaFactura;
import proyectoempresa.modeloTabla.ModeloTablaLineafactura;

/**
 *
 * @author Diego
 */
public class Facturacion extends javax.swing.JDialog {

    /** Creates new form DatosCliente */
    Factura cleintefac;
    Lineafactura lineafactura;
    ModeloTablaFactura modelo;
    IniciarReporte reporte;
    int variable;
    List<Inventario> inventarios;

    public Facturacion(java.awt.Frame parent, boolean modal, Factura fac, ModeloTablaFactura mi, int v) {
        super(parent, modal);
        setTitle("Ferretria Fhersa");
        cleintefac = fac;
        modelo = mi;
        variable = v;
        InventarioDao invdao = new InventarioDao(null);
        inventarios = invdao.buscarTodos();
        facturaDao = new FacturaDao(cleintefac);
        initComponents();
        if (variable == 2) {
            txtAbono.setVisible(true);
            lblabono.setVisible(true);
            txtSaldoActual.setVisible(true);
            lblsaldoActual.setVisible(true);
            bttDescontar.setVisible(true);
            lblvalorpagado.setVisible(true);
            txtvalorPagado.setVisible(true);
            botonCobrar.setVisible(false);
            comboTipo_Pago.setVisible(false);
            jLabel20.setVisible(false);
        } else {
            txtAbono.setVisible(false);
            lblabono.setVisible(false);
            txtSaldoActual.setVisible(false);
            lblsaldoActual.setVisible(false);
            bttDescontar.setVisible(false);
            lblvalorpagado.setVisible(false);
            txtvalorPagado.setVisible(false);
        }
        System.out.println(inventarios);
        reporte = new IniciarReporte();
        Calendar c = new GregorianCalendar();
        DateFormat fg = new SimpleDateFormat("dd/MM/yyyy");
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String fs = sdf.format(c.getTime());
        fecha.setText(fs);
        fac.setFecha(fecha.getText());
//        txtdecuentos.setText("0.0");
//        txtSubTotal.setText("0.0");
//        txtTotalCobra.setText("0.0");

        setLocationRelativeTo(null);
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        panelRectTranslucido1 = new org.edisoncor.gui.panel.PanelRectTranslucido();
        panelImageReflect1 = new org.edisoncor.gui.panel.PanelImageReflect();
        dates = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtdecuentos = new javax.swing.JTextField();
        txtSubTotal = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        txtnombresc = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        fecha = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        txtdireccion = new javax.swing.JTextField();
        comboTipo_Pago = new javax.swing.JComboBox();
        jLabel20 = new javax.swing.JLabel();
        txtcedula = new javax.swing.JFormattedTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        ModeloTablaLineafactura modelo= new ModeloTablaLineafactura(cleintefac.getLineasfac());
        tabla = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        txtcantidad = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtPrecioUnitario = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        agregarProductos = new org.edisoncor.gui.button.ButtonColoredAction();
        jLabel17 = new javax.swing.JLabel();
        txtDescuento = new javax.swing.JTextField();
        comboLiibros = new javax.swing.JComboBox();
        cantidad = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        rdioBoton = new javax.swing.JRadioButton();
        guardarObjeto = new org.edisoncor.gui.button.ButtonColoredAction();
        buttonColoredAction3 = new org.edisoncor.gui.button.ButtonColoredAction();
        jLabel14 = new javax.swing.JLabel();
        txtTotalCobrar = new javax.swing.JTextField();
        botonCobrar = new org.edisoncor.gui.button.ButtonColoredAction();
        panelImage1 = new org.edisoncor.gui.panel.PanelImage();
        lblsaldoActual = new javax.swing.JLabel();
        txtAbono = new javax.swing.JTextField();
        lblabono = new javax.swing.JLabel();
        txtSaldoActual = new javax.swing.JTextField();
        bttDescontar = new org.edisoncor.gui.button.ButtonColoredAction();
        lblvalorpagado = new javax.swing.JLabel();
        txtvalorPagado = new javax.swing.JTextField();
        buttonColoredAction1 = new org.edisoncor.gui.button.ButtonColoredAction();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setUndecorated(true);

        panelRectTranslucido1.setColorDeBorde(new java.awt.Color(255, 255, 255));
        panelRectTranslucido1.setColorDeSegundoBorde(new java.awt.Color(0, 0, 255));
        panelRectTranslucido1.setColorPrimario(new java.awt.Color(255, 51, 51));
        panelRectTranslucido1.setColorSecundario(new java.awt.Color(255, 255, 0));

        dates.setFont(new java.awt.Font("Trebuchet MS", 3, 14)); // NOI18N
        dates.setEnabled(false);

        jLabel5.setText("SubTotal:");

        jLabel6.setText("Descuentos:");

        txtdecuentos.setEditable(false);
        txtdecuentos.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.descuento}"), txtdecuentos, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtSubTotal.setEditable(false);
        txtSubTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.subtotal}"), txtSubTotal, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 5, true));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.nombresCliente}"), txtnombresc, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtnombresc.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtnombrescMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                txtnombrescMouseEntered(evt);
            }
        });
        txtnombresc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtnombrescKeyPressed(evt);
            }
        });

        jLabel2.setText("NombresCleinte");

        jLabel3.setText("Cedula");

        jLabel1.setText("Fecha:");

        fecha.setFont(new java.awt.Font("Traditional Arabic", 3, 14)); // NOI18N
        fecha.setText(".........");

        jLabel4.setFont(new java.awt.Font("Wide Latin", 3, 12)); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tekton Pro Cond", 3, 48)); // NOI18N
        jLabel10.setText("FERRETERIA FHERSA");

        jLabel11.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        jLabel11.setText("Dirección : 18 de Noviembre entre quito y Bolivar.         Telf: 2581980");

        jLabel12.setText("Direccion:");

        jLabel13.setText("Telefono: ");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.telefono}"), txtTelefono, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtTelefono.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtTelefonoMouseClicked(evt);
            }
        });
        txtTelefono.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTelefonoActionPerformed(evt);
            }
        });

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.direccion}"), txtdireccion, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtdireccion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtdireccionMouseClicked(evt);
            }
        });
        txtdireccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtdireccionActionPerformed(evt);
            }
        });

        comboTipo_Pago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CONTADO", "CREDITO" }));
        comboTipo_Pago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboTipo_PagoActionPerformed(evt);
            }
        });

        jLabel20.setText("Tipo de Pago:");

        try {
            txtcedula.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#########-#")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.cedula}"), txtcedula, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        txtcedula.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtcedulaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(41, 41, 41)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtcedula, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(txtTelefono, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtdireccion, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtnombresc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                    .addComponent(fecha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(86, 86, 86)
                                .addComponent(jLabel20)
                                .addGap(36, 36, 36)
                                .addComponent(comboTipo_Pago, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(98, 98, 98)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 654, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(244, 244, 244)
                        .addComponent(jLabel10)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addGap(34, 34, 34)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtcedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtnombresc, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(comboTipo_Pago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addGap(11, 11, 11))
        );

        jScrollPane1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 5, true));

        tabla.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true));
        tabla.setModel(modelo);
        jScrollPane1.setViewportView(tabla);

        jPanel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 5, true));

        jLabel8.setText("Descripcoin:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${lineafactura.cantidad}"), txtcantidad, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtcantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtcantidadActionPerformed(evt);
            }
        });
        txtcantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtcantidadKeyTyped(evt);
            }
        });

        jLabel9.setText("Precio Unitario:");

        txtPrecioUnitario.setEditable(false);

        jLabel7.setText("Cantidad: ");

        agregarProductos.setBackground(new java.awt.Color(153, 153, 153));
        agregarProductos.setText("AGREGAR");
        agregarProductos.setColorDeSombra(new java.awt.Color(153, 153, 255));
        agregarProductos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarProductosActionPerformed(evt);
            }
        });

        jLabel17.setText("Descuento:");

        txtDescuento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDescuentoKeyTyped(evt);
            }
        });

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${inventarios}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, comboLiibros);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.inventario}"), comboLiibros, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        comboLiibros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboLiibrosActionPerformed(evt);
            }
        });

        cantidad.setFont(new java.awt.Font("Wide Latin", 1, 14)); // NOI18N

        jLabel15.setFont(new java.awt.Font("Wide Latin", 2, 18)); // NOI18N
        jLabel15.setText("#:");

        rdioBoton.setText("IVA");
        rdioBoton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdioBotonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(comboLiibros, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPrecioUnitario, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(txtcantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rdioBoton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(jLabel17))
                    .addComponent(agregarProductos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(18, 18, 18)
                        .addComponent(cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(comboLiibros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtcantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(txtDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rdioBoton))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPrecioUnitario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(agregarProductos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        guardarObjeto.setBackground(new java.awt.Color(153, 153, 153));
        guardarObjeto.setText("GUARDAR");
        guardarObjeto.setColorDeSombra(new java.awt.Color(153, 153, 255));
        guardarObjeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarObjetoActionPerformed(evt);
            }
        });

        buttonColoredAction3.setBackground(new java.awt.Color(153, 153, 153));
        buttonColoredAction3.setText("SALIR");
        buttonColoredAction3.setColorDeSombra(new java.awt.Color(153, 153, 255));
        buttonColoredAction3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonColoredAction3ActionPerformed(evt);
            }
        });

        jLabel14.setText("Total a Cobrar:");

        txtTotalCobrar.setEditable(false);
        txtTotalCobrar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.subtotal}"), txtTotalCobrar, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        botonCobrar.setBackground(new java.awt.Color(153, 153, 153));
        botonCobrar.setText("COBRAR");
        botonCobrar.setColorDeSombra(new java.awt.Color(153, 153, 255));
        botonCobrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCobrarActionPerformed(evt);
            }
        });

        panelImage1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true), "Pago Credito", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 3, 14))); // NOI18N

        lblsaldoActual.setText("Saldo Actual:");

        lblabono.setText("Abono:");

        txtSaldoActual.setEditable(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${factura.total_pagar}"), txtSaldoActual, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        bttDescontar.setText("DESCONTAR");
        bttDescontar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttDescontarActionPerformed(evt);
            }
        });

        lblvalorpagado.setText("Valor_Pagado:");

        txtvalorPagado.setEditable(false);

        javax.swing.GroupLayout panelImage1Layout = new javax.swing.GroupLayout(panelImage1);
        panelImage1.setLayout(panelImage1Layout);
        panelImage1Layout.setHorizontalGroup(
            panelImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImage1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblsaldoActual)
                    .addComponent(lblabono))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImage1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(bttDescontar, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtAbono, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelImage1Layout.createSequentialGroup()
                        .addComponent(txtSaldoActual, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(lblvalorpagado)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtvalorPagado, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(115, 115, 115))
        );
        panelImage1Layout.setVerticalGroup(
            panelImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImage1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAbono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblabono))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bttDescontar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelImage1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblsaldoActual)
                    .addComponent(txtSaldoActual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblvalorpagado)
                    .addComponent(txtvalorPagado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        buttonColoredAction1.setText("Eliminar");
        buttonColoredAction1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonColoredAction1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelImageReflect1Layout = new javax.swing.GroupLayout(panelImageReflect1);
        panelImageReflect1.setLayout(panelImageReflect1Layout);
        panelImageReflect1Layout.setHorizontalGroup(
            panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImageReflect1Layout.createSequentialGroup()
                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImageReflect1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panelImageReflect1Layout.createSequentialGroup()
                        .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelImageReflect1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane1)
                                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(panelImageReflect1Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addComponent(buttonColoredAction1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(95, 95, 95)
                                .addComponent(guardarObjeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(44, 44, 44)
                                .addComponent(botonCobrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelImageReflect1Layout.createSequentialGroup()
                                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(txtdecuentos)
                                        .addComponent(txtSubTotal))
                                    .addComponent(buttonColoredAction3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtTotalCobrar, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE))
                            .addComponent(panelImage1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
            .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelImageReflect1Layout.createSequentialGroup()
                    .addGap(260, 260, 260)
                    .addComponent(dates)
                    .addContainerGap(744, Short.MAX_VALUE)))
        );
        panelImageReflect1Layout.setVerticalGroup(
            panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelImageReflect1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panelImage1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImageReflect1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtdecuentos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(19, 19, 19)
                        .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(txtTotalCobrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panelImageReflect1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonColoredAction3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonCobrar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(guardarObjeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonColoredAction1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(36, Short.MAX_VALUE))
            .addGroup(panelImageReflect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelImageReflect1Layout.createSequentialGroup()
                    .addGap(87, 87, 87)
                    .addComponent(dates, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(579, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout panelRectTranslucido1Layout = new javax.swing.GroupLayout(panelRectTranslucido1);
        panelRectTranslucido1.setLayout(panelRectTranslucido1Layout);
        panelRectTranslucido1Layout.setHorizontalGroup(
            panelRectTranslucido1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRectTranslucido1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelImageReflect1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelRectTranslucido1Layout.setVerticalGroup(
            panelRectTranslucido1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRectTranslucido1Layout.createSequentialGroup()
                .addComponent(panelImageReflect1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelRectTranslucido1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelRectTranslucido1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents
    FacturaDao facturaDao;
    LineaFacturaDao linefacturaDao;
    private void guardarObjetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarObjetoActionPerformed
        try {
            if (variable == 1) {
                JOptionPane.showMessageDialog(this, "NEW INVOICE");
                modelo.getFilas().add(cleintefac);
                //  System.out.println("Este es mi Id>>>" + cleintefac.getId());
                cleintefac.setId_cliente(cleintefac.getId());
                System.out.println(cleintefac.getId_cliente());
                GeneraLetras letras = new GeneraLetras();
                cleintefac.setTotaLetras(letras.Convertir(cleintefac.getSubtotal(), true));
                System.out.println(letras.Convertir(cleintefac.getSubtotal(), true));
                JOptionPane.showMessageDialog(null, letras.Convertir(cleintefac.getSubtotal(), true));
                facturaDao.update();
                modelo.fireTableDataChanged();

                if (comboTipo_Pago.getSelectedItem().equals("CREDITO")) {
                    reporte.ejecutarReportePagoCredito("" + cleintefac.getId_cliente());
                }
            } else {

                facturaDao.update();
                reporte.ejecutarReportePagoCredito("" + cleintefac.getId_cliente());
                lineafactura.agregar(cleintefac);
                modelo.fireTableDataChanged();
                dispose();
            }

        } catch (Exception e) {
        }


    }//GEN-LAST:event_guardarObjetoActionPerformed

    private void buttonColoredAction3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonColoredAction3ActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_buttonColoredAction3ActionPerformed
    ContenedorReporteGeneralCuentasDao rad;
    ContenedorReporteGeneralCuentas ra;
    private void agregarProductosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregarProductosActionPerformed
        if (txtPrecioUnitario.getText().equals("")||(comboLiibros.getSelectedIndex()==-1)) {
            JOptionPane.showMessageDialog(null, "No ha seleccionado un  Producto");
        } else {
            Inventario inventario = (Inventario) comboLiibros.getSelectedItem();
            InventarioDao inDao = new InventarioDao(inventario);
            ContenedorReporteGeneralCuentas rprimero = null;
            if (!txtnombresc.getText().equals("") || !txtTelefono.getText().equals("") || !txtcantidad.getText().equals("") || !txtPrecioUnitario.getText().equals("")) {
                lineafactura = new Lineafactura();
                ra = new ContenedorReporteGeneralCuentas();
                rad = new ContenedorReporteGeneralCuentasDao(ra);
               Double b=0.0;
        Double b1=0.0;

        if (rdioBoton.isSelected() == true) {
            b= Double.valueOf(txtcantidad.getText())*Double.valueOf(txtPrecioUnitario.getText());
            b1= b*0.12;
           lineafactura.setIva(String.valueOf(b1));
           JOptionPane.showMessageDialog(null,b1);
            rdioBoton.setSelected(false);
            } else {
           obtenerIva=String.valueOf("0.0");
           JOptionPane.showMessageDialog(null,"0.0");
        }
                lineafactura.setCantidad(Integer.parseInt(txtcantidad.getText()));
                ra.setCantidad_factura("" + Integer.parseInt(txtcantidad.getText()));
                lineafactura.setDescripcion(inventario.getNombreLibro());
                ra.setTitulo_Descripcion(inventario.getNombreLibro());
                lineafactura.setPrecioUnitario(Double.valueOf(txtPrecioUnitario.getText()));
                ra.setPrecio_factura("" + Double.valueOf(txtPrecioUnitario.getText()));
                ra.setFecha(cleintefac.getFecha());
                Double pu = 0.0;
                Double pd = 0.0;
                if (!txtDescuento.getText().equals("")) {
                    lineafactura.setDescuento(Double.parseDouble(txtDescuento.getText()));
                } else {
                    lineafactura.setDescuento(Double.parseDouble("0.0"));
                }
                ra.setDescuento(lineafactura.getDescuento() + "");
                Double d = lineafactura.getPrecioUnitario() * Double.valueOf(lineafactura.getDescuento());
                JOptionPane.showMessageDialog(null, d);
                lineafactura.setTotaldescuento("" + (lineafactura.getPrecioUnitario() * lineafactura.getCantidad()) * Double.valueOf(lineafactura.getDescuento()));
                ra.setIngresos(String.valueOf(((lineafactura.getPrecioUnitario() - d) * lineafactura.getCantidad())));
                lineafactura.setTotalCobrar(String.valueOf(((lineafactura.getPrecioUnitario() - d) * lineafactura.getCantidad())));
                JOptionPane.showMessageDialog(null, lineafactura.getTotalCobrar());
                ModeloTablaLineafactura modell = (ModeloTablaLineafactura) tabla.getModel();

                linefacturaDao = new LineaFacturaDao(lineafactura);

                try {
                    if (variable == 1) {
                        cleintefac.agregar(lineafactura);
                        lineafactura.agregar(cleintefac);
                        inventario.setCantidad("" + (Integer.parseInt(inventario.getCantidad()) - Integer.parseInt(txtcantidad.getText())));
                        facturaDao.persistence();
                        rad.persistence();
                        if (rad.findById(1l) != null) {
                            rprimero = rad.findById(1l);
                            Long a = lineafactura.getId_producto();
                            rprimero.setFactura_Numer(String.valueOf(a += 1));
                            //   JOptionPane.showMessageDialog(null, ">>>>>>>>>"+ra.getFactura_Numer());
                            rad.update();
                        }
                        if (rad.findById(1l) != null) {
                            rprimero = rad.findById(1l);
                            rprimero.setSumaingresos("" + (Double.valueOf(rprimero.getSumaingresos()) + Double.valueOf(ra.getIngresos())));
                            rad.update();
                        }
                        // System.out.println(rad.findById(1l) + "Primer Objeto");
                        linefacturaDao.persistence();
                        modell.fireTableDataChanged();
                        linefacturaDao.persistence();
                        inDao.update();
                        cleintefac.setDescuento(String.valueOf(cleintefac.descuentoReal()));
                        cleintefac.setSubtotal(String.valueOf(cleintefac.subTotal()));
                        cleintefac.setTotal_pagar(String.valueOf(cleintefac.subTotal()));
                        facturaDao.update();
                        txtdecuentos.setText(String.valueOf(cleintefac.getDescuento()));
                        txtSubTotal.setText(String.valueOf(cleintefac.getSubtotal()));
                        txtTotalCobrar.setText(String.valueOf(cleintefac.getSubtotal()));
                        txtSaldoActual.setText(String.valueOf(cleintefac.getSubtotal()));
                        JOptionPane.showMessageDialog(this, "Nuevo Producto");
                    } else {
                        cleintefac.agregar(lineafactura);
                        lineafactura.agregar(cleintefac);
                        facturaDao.persistence();
                        linefacturaDao.persistence();
                        linefacturaDao.update();
                        // cleintefac.agregar(lineafactura);
                        modell.fireTableDataChanged();

                    }

                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e);
                }
                txtcantidad.setText("");
                txtPrecioUnitario.setText("");
            } else {

                JOptionPane.showMessageDialog(null, "Llene los Campos Vacios para Realizar la Factura");
            }
        }
    }//GEN-LAST:event_agregarProductosActionPerformed

    private void txtTelefonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTelefonoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTelefonoActionPerformed

    private void txtdireccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtdireccionActionPerformed
        // TODO add your handling code here:
        txtdireccion.setText("");
    }//GEN-LAST:event_txtdireccionActionPerformed

    private void botonCobrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCobrarActionPerformed
        // TODO add your handling code here:
        String c = "";
        String cedula = "";
        c = c + txtcedula.getText().trim();
        System.out.println(c);
        if (c.equals("-")) {
            JOptionPane.showMessageDialog(null, "No ha Ingresado numero de  Cedula ");
        } else {
            new CobroFactura(new JFrame(), true, cleintefac, txtTotalCobrar.getText(), "" + cleintefac.getId_cliente(), facturaDao).setVisible(true);
            dispose();
        }
    }//GEN-LAST:event_botonCobrarActionPerformed

    private void comboLiibrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboLiibrosActionPerformed
        // TODO add your handling code here:

        if (comboLiibros.getSelectedIndex() != -1) {
            Inventario inventario = (Inventario) comboLiibros.getSelectedItem();
            txtPrecioUnitario.setText(inventario.getP_unidad());
            cantidad.setText(inventario.getCantidad());
        } else {
            //JOptionPane.showMessageDialog(null,"Debe Seleccionar Un Producto");
        }
    }//GEN-LAST:event_comboLiibrosActionPerformed

    private void comboTipo_PagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTipo_PagoActionPerformed
        // TODO add your handling code here:
        if (comboTipo_Pago.getSelectedItem().equals("CREDITO")) {
            txtAbono.setVisible(true);
            lblabono.setVisible(true);
            txtSaldoActual.setVisible(true);
            lblsaldoActual.setVisible(true);
            bttDescontar.setVisible(true);
            lblvalorpagado.setVisible(true);
            txtvalorPagado.setVisible(true);
            botonCobrar.setVisible(false);
        } else {
            txtAbono.setVisible(false);
            lblabono.setVisible(false);
            txtSaldoActual.setVisible(false);
            lblsaldoActual.setVisible(false);
            bttDescontar.setVisible(false);
            lblvalorpagado.setVisible(false);
            txtvalorPagado.setVisible(false);
            botonCobrar.setVisible(true);
        }
        cleintefac.setTipopago(String.valueOf(comboTipo_Pago.getSelectedItem()).toString());
    }//GEN-LAST:event_comboTipo_PagoActionPerformed

    private void bttDescontarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttDescontarActionPerformed
        try {
            if (Double.parseDouble(cleintefac.getTotal_pagar()) == 0.0) {
                JOptionPane.showMessageDialog(null, "Pago Realizado Completamente");
                botonCobrar.setVisible(true);
            } else {
                String valor = String.valueOf(Double.parseDouble(cleintefac.getTotal_pagar()) - Double.parseDouble(txtAbono.getText()));
                txtSaldoActual.setText(valor);

                cleintefac.setAbono("" + (Double.parseDouble(cleintefac.getAbono()) + Double.parseDouble(txtAbono.getText())));
                facturaDao.update();
                txtvalorPagado.setText(cleintefac.getAbono());
                if (cleintefac.getAbono() == cleintefac.getSubtotal()) {
                    botonCobrar.setVisible(true);
                }
                modelo.fireTableStructureChanged();
            }
        } catch (Exception ex) {
            Logger.getLogger(Facturacion.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_bttDescontarActionPerformed

    private void txtcantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcantidadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtcantidadActionPerformed

    private void txtcantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtcantidadKeyTyped
        // TODO add your handling code here:
        char a = evt.getKeyChar();
        if (Character.isDigit(a)) {
        } else {
            evt.consume();
        }
    }//GEN-LAST:event_txtcantidadKeyTyped

    private void txtDescuentoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescuentoKeyTyped
        // TODO add your handling code here:
        char a = evt.getKeyChar();
        if (Character.isDigit(a) || a == '.') {
        } else {
            evt.consume();
        }
    }//GEN-LAST:event_txtDescuentoKeyTyped

    private void txtnombrescKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtnombrescKeyPressed
    }//GEN-LAST:event_txtnombrescKeyPressed

    private void txtnombrescMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtnombrescMouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_txtnombrescMouseEntered

    private void txtnombrescMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtnombrescMouseClicked
        // TODO add your handling code here:
        txtnombresc.setText("");
    }//GEN-LAST:event_txtnombrescMouseClicked

    private void txtTelefonoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtTelefonoMouseClicked
        // TODO add your handling code here:
        txtTelefono.setText("");
    }//GEN-LAST:event_txtTelefonoMouseClicked

    private void txtdireccionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtdireccionMouseClicked
        // TODO add your handling code here:
        txtdireccion.setText("");
    }//GEN-LAST:event_txtdireccionMouseClicked
    FacturaDao fac = new FacturaDao(null);
    private void txtcedulaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtcedulaMouseClicked
        String c = "";
        c = c + txtcedula.getText().trim();
        List<Factura> lista;
        System.out.println(c);
        if (c.equals("-")) {
            JOptionPane.showMessageDialog(null, "No ha Ingresado numero de  Cedula");
        } else {
            System.out.println(c + "//////");
            if (cleintefac.validarCedula(c)) {
                try {
                    Factura fact;
                    if (fac.buscarCedula(c).isEmpty()) {
                        JOptionPane.showMessageDialog(null, "Es La Primera Factura del Cliente");
                    } else {
                        fact = fac.buscarCedula(c).get(0);
                        System.out.println(fact + "//////////////fact");
                        txtnombresc.setText(fact.getNombresCliente());
                        txtTelefono.setText(fact.getTelefono());
                        txtdireccion.setText(fact.getDireccion());
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e + "-------------");
                }
            } else {
                JOptionPane.showMessageDialog(null, "Cedula Incorrecta");
                txtnombresc.setText("");
                txtTelefono.setText("");
                txtdireccion.setText("");
            }
        }
    }//GEN-LAST:event_txtcedulaMouseClicked
    LineaFacturaDao lfd;
    private void buttonColoredAction1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonColoredAction1ActionPerformed
        // TODO add your handling code here:
        ModeloTablaLineafactura model = (ModeloTablaLineafactura) tabla.getModel();
        Factura fact;
        FacturaDao fd;
        int[] selected = tabla.getSelectedRows();
        System.out.println(selected[0]);
        int op = JOptionPane.showConfirmDialog(this, "¿REALMENTE DESEA ELIMINARLO?");
        if (op == 0) {
            List<Lineafactura> toRemove = new ArrayList<Lineafactura>(selected.length);
            try {
                double cont = 0.0;
                double cont2 = 0.0;
                for (int idx = 0; idx < selected.length; idx++) {
                    Lineafactura lf = model.getFilas().get(tabla.convertRowIndexToModel(selected[idx]));
                    lfd = new LineaFacturaDao(lf);
                    cont = cont + Double.valueOf(lf.getTotalCobrar());
                    cont2 = cont2 + Double.valueOf(lf.getTotaldescuento());
                    // System.out.println(lf);
                    toRemove.add(lf);
                    lfd.remover();

                }
                model.getFilas().removeAll(toRemove);
                model.fireTableDataChanged();
                JOptionPane.showMessageDialog(null, cont);
                JOptionPane.showMessageDialog(null, cont2);
                cleintefac.setDescuento(String.valueOf(Double.valueOf(cleintefac.getDescuento()) - cont2));
                cleintefac.setSubtotal(String.valueOf(Double.valueOf(cleintefac.getSubtotal()) - cont));
                facturaDao.update();
                txtdecuentos.setText(String.valueOf(cleintefac.getDescuento()));
                txtSubTotal.setText(String.valueOf(cleintefac.getSubtotal()));
                txtTotalCobrar.setText(String.valueOf(cleintefac.getSubtotal()));
                txtSaldoActual.setText(String.valueOf(cleintefac.getSubtotal()));
                facturaDao.update();
                JOptionPane.showMessageDialog(null, "Se ha Eliminado ");
            } catch (Exception ex) {
                Logger.getLogger(TablaInventario.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
        }

    }//GEN-LAST:event_buttonColoredAction1ActionPerformed
    String obtenerIva="0.0";
    private void rdioBotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdioBotonActionPerformed
        // TODO add your handling code here
        Double b=0.0;
        Double b1=0.0;

        if (rdioBoton.isSelected() == true) {
            if (!txtcantidad.getText().equals("")&&!txtPrecioUnitario.getText().equals("")) {
            b= Double.valueOf(txtcantidad.getText())*Double.valueOf(txtPrecioUnitario.getText());
           // JOptionPane.showMessageDialog(null,b);
            b1= b*0.12;
           // JOptionPane.showMessageDialog(null,b1);
           obtenerIva=String.valueOf(b1);
          //  JOptionPane.showMessageDialog(null,lineafactura.getIva());
            
            }else{
          //  JOptionPane.showMessageDialog(null,"Olvido poner la Cantidad o seleccionar el Producto");
            rdioBoton.setSelected(false);
            }
        } else {
           obtenerIva=String.valueOf("0.0");
        }
    }//GEN-LAST:event_rdioBotonActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                DatosCliente dialog = new DatosCliente(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonColoredAction agregarProductos;
    private org.edisoncor.gui.button.ButtonColoredAction botonCobrar;
    private org.edisoncor.gui.button.ButtonColoredAction bttDescontar;
    private org.edisoncor.gui.button.ButtonColoredAction buttonColoredAction1;
    private org.edisoncor.gui.button.ButtonColoredAction buttonColoredAction3;
    private javax.swing.JLabel cantidad;
    private javax.swing.JComboBox comboLiibros;
    private javax.swing.JComboBox comboTipo_Pago;
    private javax.swing.JLabel dates;
    private javax.swing.JLabel fecha;
    private org.edisoncor.gui.button.ButtonColoredAction guardarObjeto;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblabono;
    private javax.swing.JLabel lblsaldoActual;
    private javax.swing.JLabel lblvalorpagado;
    private org.edisoncor.gui.panel.PanelImage panelImage1;
    private org.edisoncor.gui.panel.PanelImageReflect panelImageReflect1;
    private org.edisoncor.gui.panel.PanelRectTranslucido panelRectTranslucido1;
    private javax.swing.JRadioButton rdioBoton;
    private javax.swing.JTable tabla;
    private javax.swing.JTextField txtAbono;
    private javax.swing.JTextField txtDescuento;
    private javax.swing.JTextField txtPrecioUnitario;
    private javax.swing.JTextField txtSaldoActual;
    private javax.swing.JTextField txtSubTotal;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtTotalCobrar;
    private javax.swing.JTextField txtcantidad;
    private javax.swing.JFormattedTextField txtcedula;
    private javax.swing.JTextField txtdecuentos;
    private javax.swing.JTextField txtdireccion;
    private javax.swing.JTextField txtnombresc;
    private javax.swing.JTextField txtvalorPagado;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public Factura obtenerFactura() {
        return new Factura(txtnombresc.getText(), txtdireccion.getText(), txtTelefono.getText(), txtcedula.getText(), fecha.getText());

    }

    public Lineafactura getLineafactura() {
        return lineafactura;
    }

    public List<Inventario> getInventarios() {
        return inventarios;
    }

    public void setInventarios(List<Inventario> inventarios) {
        this.inventarios = inventarios;
    }

    public void setLineafactura(Lineafactura lineafactura) {
        this.lineafactura = lineafactura;
    }

    public Factura getFactura() {
        return cleintefac;
    }

    public void setFactura(Factura factura) {
        this.cleintefac = factura;
    }

    public static void main(String[] args) {
        new TablaCliente(new JFrame(), true);
    }
}
